# CC <e11907086@student.tuwien.ac.at>
# client program name is $(PROG_CLIENT)
# server program name is $(PROG_SERVER)
CFLAGS:= -Wall -std=c99 -pedantic -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_POSIX_C_SOURCE=200809L
CXX:= gcc
PROG_CLIENT:= client
PROG_SERVER:= server

LDFLAGS:=
LDFLAGS+= -lz

OBJS_CLIENT:= zutil.o parser.o url.o http.o client.o
OBJS_SERVER:= zutil.o parser.o http.o server.o

all: $(PROG_CLIENT) $(PROG_SERVER)

%.o: src/%.c
	$(CXX) $(CFLAGS) -g -c $<

$(PROG_CLIENT): $(OBJS_CLIENT)
	$(CXX) $(CFLAGS) $(OBJS_CLIENT) -o $(PROG_CLIENT) $(LDFLAGS)

$(PROG_SERVER): $(OBJS_SERVER)
	$(CXX) $(CFLAGS) $(OBJS_SERVER) -o $(PROG_SERVER) $(LDFLAGS)

install: all
	@echo installing executable file to ${DESTDIR}${PREFIX}/bin
	@mkdir -p ${DESTDIR}${PREFIX}/bin
	@cp -f ${PROG_CLIENT} ${DESTDIR}${PREFIX}/bin
	@cp -f ${PROG_SERVER} ${DESTDIR}${PREFIX}/bin
	@chmod 755 ${DESTDIR}${PREFIX}/bin/${PROG_CLIENT}
	@chmod 755 ${DESTDIR}${PREFIX}/bin/${PROG_SERVER}

uninstall:
	@echo removing executable file from ${DESTDIR}${PREFIX}/bin
	@rm -f ${DESTDIR}${PREFIX}/bin/${PROG_CLIENT}
	@rm -f ${DESTDIR}${PREFIX}/bin/${PROG_SERVER}

clean:
	rm $(PROG_CLIENT) $(PROG_SERVER) *.o